<?php
/**
 * 发送祝福
 */
require_once dirname(dirname(__DIR__)) . "/common.php";

use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\cls\tom\Config;
use app\model\Activity;

$host_id = $_POST['host_id'];//主持人id
$select_person_id = $_POST['select_person_id'];//拜年对象id
if (empty($host_id) || empty($select_person_id)) {
    Response::output(-1, "缺少参数");
}
// 本地缓存

//$shmCache = SysResource::getShmCache();
//先从缓存里读取数据
$redis_cache_key = REDIS_PREFIX . "TEMPLATE_PHOTO_" . $host_id . $select_person_id;
//$redis_cache_data = $shmCache->get($redis_cache_key);

$redis_cache_data = "";

if (!empty($redis_cache_data)) {
    // 本地缓存数据
    $data = json_decode($redis_cache_data);
    Response::output(0, "查询成功shm", $data, count($data));
} else {

    $redis = SysResource::getRedis();
    $redis_cache_data = $redis->get($redis_cache_key);
    if ($redis_cache_data) {
        //读取缓存里的数据
//        $shmCache->set($redis_cache_key,$redis_cache_data,10);
        $data = json_decode($redis_cache_data);
        Response::output(0, "查询成功red", $data, count($data));
    } else {

        //查询数据库
        try {
            $db = SysResource::getDB(false);
            $Activity = new Activity($db);
            $host = $Activity->one("activity_host_name", ['id' => $host_id], "id,name");
            $person = $Activity->one("activity_select_person", ['id' => $select_person_id], "id,name");
            $data = $Activity->wangchun_one(['wangchun_host' => $host_id, "wangchun_select_person" => $select_person_id], "id,wangchun_host,wangchun_select_person,wangchun_host_name,wangchun_select_person_name,wangchun_video_url,wangchun_pic,wangchun_share_pic,wangchun_title,wangchun_duration,wangchun_width,wangchun_height");
//            var_dump(1234321);exit;
            if (empty($data)) {
                Response::output(-1, "服务内部有错");
            }
            $data['wangchun_huati'] = "央视虚拟主持人";
            $data['wangchun_host_name'] = $host['name'];
            $data['wangchun_select_person_name'] = $person['name'];

//            $shmCache->set($redis_cache_key,json_encode($data),10);
            $redis->setex($redis_cache_key, 15, json_encode($data));
            Response::output(0, "查询成功", $data);
        } catch (DBException $e) {
            Response::output(-1, "系统忙碌中");
        }
    }
}

